import UIView from "../../../../quick/core/ui/UIView";
import { inject } from "../../../../quick/defines/Decorators";
import { Macro } from "../../../../quick/defines/Macros";
import { TankBettle } from "../data/TankBattleConfig";

const { ccclass, property } = cc._decorator;

@ccclass
export default class TankBattleStartView extends UIView {
    public static getPrefabUrl() {
        return "prefabs/TankBattleStartView";
    }

    /**@description 选择模式的小坦克 */
    @inject("tank",cc.Node,"content")
    private selectTank: cc.Node = null;
    /**@description 单人 */
    @inject("player",cc.Node,"content")
    private singlePlayer: cc.Node = null;
    /**@description 多人 */
    @inject("players",cc.Node,"content")
    private doublePalyers: cc.Node = null;
    protected logic : TankBattleLogic = null!;
    onLoad() {
        super.onLoad();
        if ( this.args && this.args.length > 0 ){
            this.logic = this.args[0];
         }
        this.selectTank.y = this.singlePlayer.y;
    }

    protected onKeyBackUp(ev: cc.Event.EventKeyboard) {
        super.onKeyBackUp(ev);
        App.entryManager.enterBundle(Macro.BUNDLE_HALL);
    }

    protected onKeyUp(ev: cc.Event.EventKeyboard) {
        super.onKeyUp(ev);
        if ( this.logic ){
            this.logic.onKeyUp(ev,TankBettle.ViewType.START_VIEW,this);
        }
    }

    isSingle(){
        return this.selectTank.position.y == this.singlePlayer.position.y;
    }

    updateSelectTank( isSingle : boolean){
        if ( isSingle ){
            this.selectTank.setPosition(new cc.Vec3(this.selectTank.position.x,this.singlePlayer.position.y,this.selectTank.position.z));
        }else{
            this.selectTank.setPosition(new cc.Vec3(this.selectTank.position.x,this.doublePalyers.position.y,this.selectTank.position.z));
        }
    }

    onShow(): void {
        this.enabledKeyUp = true;
        this.audioHelper.stopMusic();
        super.onShow();
    }

    onClose(): void {
        this.enabledKeyUp = false;
        super.onClose();
    }
}
